/**
*      author: Y_Yao
*      created: 2024-12-13 22:13:43
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 9 + 7;
int a[N][N],dp[N][N][N][N];
int n;

void solve()
{
    cin >> n;
    int x,y,val;
    while(cin >> x >> y >> val)
    {
        if(x == 0 && y == 0 && val == 0)
        {
            break;
        }

        a[x][y] = val;
    }

    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= n;j++)
        {
            for(int k = 1;k <= n;k++)
            {
                for(int m = 1;m <= n;m++)
                {
                    dp[i][j][k][m] = max(max(dp[i-1][j][k-1][m],dp[i-1][j][k][m-1]),max(dp[i][j-1][k-1][m],dp[i][j-1][k][m-1])) + a[i][j] + a[k][m];
                    if(i == k && j == m)
                        dp[i][j][k][m] -= a[i][j];
                }
            }
        }
    }

    cout << dp[n][n][n][n] << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}